package com.abyss.bprecord;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.abyss.bprecord.Bean.BPInfoBean;

import java.util.ArrayList;
import java.util.List;

public class ListAdapter extends Adapter<ListAdapter.ViewHolder> {
    private Context context;
    private List<BPInfoBean> mDatas;


    public ListAdapter(Context context, List<BPInfoBean> mDatas) {
        this.context = context;
        this.mDatas = mDatas;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_list, viewGroup, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        BPInfoBean bpInfoBean = mDatas.get(i);
        viewHolder.tvTime.setText(bpInfoBean.getTime());
        viewHolder.tvSP.setText(bpInfoBean.getSystolicPressure());
        viewHolder.tvDp.setText(bpInfoBean.getPulse());
        viewHolder.tvPluse.setText(bpInfoBean.getPulse());

    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvTime;
        TextView tvSP;
        TextView tvDp;
        TextView tvPluse;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvTime = itemView.findViewById(R.id.tv_time);
            tvSP = itemView.findViewById(R.id.tv_SystolicPressure);
            tvDp = itemView.findViewById(R.id.tv_DiastolicPressure);
            tvPluse = itemView.findViewById(R.id.tv_pulse);
        }
    }
}
